<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title>后台管理系统</title>
	    <meta name="author" content="BaiYY"/>
	    <meta charset="utf-8">
	    <meta http-equiv="X-UA-Compatible" content="IE=edge">
	    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
	    <meta name="renderer" content="webkit">
	    <link rel="stylesheet" type="text/css" href="__PUBLIC__/admin/css/bootstrap.min.css"/>
	    <link rel="stylesheet" type="text/css" href="__PUBLIC__/admin/css/Font/css/font-awesome.min.css"/>
	    <link rel="stylesheet" type="text/css" href="__PUBLIC__/admin/css/index.css"/>
	    <script type="text/javascript" src="__PUBLIC__/admin/js/jquery.js"></script>
	    <script type="text/javascript" src="__PUBLIC__/admin/js/bootstrap.min.js"></script>
	    <script type="text/javascript" src="__PUBLIC__/admin/js/index.js"></script>
	</head>
	<body>
		<!--右边侧栏开始-->
		<div class="right-sidebar" id="agentUserRatio" style="max-width: 1200px;">
			<ul class="nav nav-tabs" style="margin-bottom: 16px" role="tablist">
				<li role="presentation" class="active"><a href="agentUserRatio.html">后台返例设置</a></li>
				<li role="presentation" id="onLineRatio"><a href="onLineRatio.html">{:L(GAME_ONLINE_RATIO)}</a></li>
				<!--<li role="presentation"><a href="agentUserExpiration.html">过期时间</a></li>
				<li role="presentation"><a href="agentLines.html">透支设置</a></li>-->
			</ul>
			<h3>说明:</h3>
			<p><strong>一级代理</strong>已是最高代理，只享有返利</p>
			<p><strong>二级代理</strong>只能向一级代理设置返利</p>
			<if condition="$level gt 2">
			<p><strong>三级代理</strong>可以分别对一二级代理设置不同的返利</p>
			</if>
			<div class="row">
				<div class="form-group col-xs-12">
					<div class="input-group">
						<div class="input-group-addon">二级向一级设置</div>
						<input type="number" min="0" max="100" class="form-control" value="{$slevel}" name="srebate" id="srebate">
						<div class="input-group-addon">%</div>
					</div>
				</div>
				<if condition="$level gt 2">
				<div class="form-group col-xs-12">
					<div class="input-group">
						<div class="input-group-addon">三级向一级设置</div>
						<input type="number" min="0" max="100" class="form-control" value="{$tlevell}" name="trebate" id="trebate">
						<div class="input-group-addon">%</div>
					</div>
				</div>
				<div class="form-group col-xs-12">
					<div class="input-group">
						<div class="input-group-addon">三级向二级设置</div>
						<input type="number" min="0" max="100" class="form-control" value="{$tlevel}" name="trebatel" id="trebatel">
						<div class="input-group-addon">%</div>
					</div>
				</div>
				</if>
				<div class="col-xs-6"> <button type="submit" id="submit" class="btn btn-primary">设置</button></div>
			</div>
		</div>
		<script type="text/javascript">
            var onLineRatio = $.trim($("#onLineRatio").text());
            if(onLineRatio == '' || onLineRatio == 'GAME_ONLINE_RATIO') {
                $("#onLineRatio").hide();
            }
			$("#submit").on("click",function(){
				var srebate = $.trim($("#srebate").val());
				var trebate = $.trim($("#trebate").val());
				var trebatel = $.trim($("#trebatel").val());
				var level = "{$level}";
				var datas = '';
				if(level == 2) {
				    datas = {'srebate':srebate}
					if(srebate == '') {
					    alert("设置不能为空！");
                        window.location.href="{:U('Admin/Main/agentUserRatio')}";
                        return false;
					}
					if(parseInt(srebate) < 0) {
                        alert("代理比例不能小于0");
                        window.location.href="{:U('Admin/Main/agentUserRatio')}";
					}
					if(parseInt(srebate) > 100) {
                        alert("代理比例不能小于0");
                        window.location.href="{:U('Admin/Main/agentUserRatio')}";
                        return false;
					}
				}else{
				    datas = {'srebate':srebate,'trebate':trebate,'trebatel':trebatel};
                    if(srebate == '' || trebate == '' || trebatel == '') {
                        alert("任何一级设置不能为空");
                        return false;
                    }

                    if(parseInt(srebate) < 0 || parseInt(trebate) < 0 || parseInt(trebatel) < 0) {
                        alert("代理比例不能小于0");
                        window.location.href="{:U('Admin/Main/agentUserRatio')}";
                        return false;
                    }

                    if(parseInt(srebate) > 100 || parseInt(trebate) > 100 || parseInt(trebatel) > 100) {
                        alert("代理比例不能大于100");
                        window.location.href="{:U('Admin/Main/agentUserRatio')}";
                        return false;
                    }
				}
				var url= "{:U('Admin/Main/agentRatioSet')}";
				$.ajax({
					type:"post",
					url:url,
					dataType:"json",
					data:datas,
					success:function(data) {
//						console.log(data);
						if(data == 'success') {
							alert("设置成功！");
                            window.location.href="{:U('Admin/Main/agentUserRatio')}";
						}else if(data == 'error') {
							alert("设置失败！");
                            window.location.href="{:U('Admin/Main/agentUserRatio')}";
                        }
					}
				});
			});
		</script>
	</body>
</html>
